cqjs.component('selectionField', {
    template: `
        <el-select v-model="data.data[$props.field.name]"
                   @change="handleChange"
                   :placeholder="$props.placeholder"
                   style='width:100%'>
            <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
        </el-select>
    `,
    props: ['field', 'data', 'placeholder'],
    data() {
        const options = [];
        if (!this.$attrs.required && !this.field.required) {
            options.push({ value: '', label: '' });
        }
        for (const value in this.field.options) {
            options.push({ value: value, label: this.field.options[value]?.t() });
        }
        return {
            options
        }
    },
    methods: {
        handleChange(v) {
            this.data.dirty[this.field.name] = v;
        }
    }
});